package com.wgh.api.client.inventory;

import com.wgh.api.client.fallback.InventoryClientFallback;
import com.wgh.inventory.dto.InventoryDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * 库存服务客户端接口
 */
@FeignClient(name = "shop-inventory", fallback = InventoryClientFallback.class)
public interface InventoryClient {

    /**
     * 查询商品库存
     */
    @GetMapping("/inventory/{productId}")
    InventoryDTO getInventoryByProductId(@PathVariable("productId") Long productId);

    /**
     * 批量查询商品库存
     */
    @GetMapping("/inventory/batch")
    List<InventoryDTO> getInventoryListByProductIds(@RequestParam("productIds") List<Long> productIds);

    /**
     * 扣减库存
     */
    @PostMapping("/inventory/deduct")
    Boolean deductInventory(@RequestBody Map<Long, Integer> inventoryMap);

    /**
     * 增加库存
     */
    @PostMapping("/inventory/increase")
    Boolean increaseInventory(@RequestBody Map<Long, Integer> inventoryMap);

    /**
     * 查询库存状态
     */
    @GetMapping("/inventory/status")
    Map<Long, Boolean> checkInventoryStatus(@RequestParam("productIds") List<Long> productIds,
                                           @RequestParam("quantities") List<Integer> quantities);
}